<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta charset="UTF-8">
		<title>Title</title>
		<link rel="stylesheet" href="../../../component/pear/css/pear.css" />
	</head>
	<body>
		<form class="layui-form" action="" lay-filter="role-edit">
			<div class="mainBox">
				<div class="main-container">
					<div class="main-container">
						<div class="layui-form-item layui-hide">
							<label class="layui-form-label">编号</label>
							<div class="layui-input-block">
								<input type="text" name="id" lay-verify="id" autocomplete="off" placeholder="请输入账户" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">账户</label>
							<div class="layui-input-block">
								<input type="text" name="name" lay-verify="name" autocomplete="off" placeholder="请输入账户" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">备注</label>
							<div class="layui-input-block">
								<textarea type="text" name="remark" lay-verify="remark" autocomplete="off" placeholder="请输入标题" class="layui-input layui-textarea"></textarea>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="bottom">
				<div class="button-container">
					<button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="user-save">
						<i class="layui-icon layui-icon-ok"></i>
						提交
					</button>
					<button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
						<i class="layui-icon layui-icon-refresh"></i>
						重置
					</button>
				</div>
			</div>
		</form>
		<script src="../../../component/layui/layui.js"></script>
		<script src="../../../component/pear/pear.js"></script>
		<script>
			layui.use(['form', 'jquery','context','permission','popup'], function() {
				let form = layui.form;
				let $ = layui.jquery;
				let context = layui.context;
				let popup = layui.popup;
				
				let basePath = context.get("base-path");
				
				let currentId = parent.layui.jquery("#id").val();
				$("#id").val(currentId);

				$.ajax({
					url: basePath + '/api/role/profile/'+ currentId,
					dataType: 'json',
					contentType: 'application/json',
					type: 'get',
					success: function(result) {
						form.val("user-role", result.data);
					}
				})

				form.on('submit(user-save)', function(data) {
					
					if(data.field.gender=="0") data.field.gender = 0;
					else data.field.gender = 1;
					
					$.ajax({
						url: basePath + '/api/role/modify',
						data: JSON.stringify(data.field),
						dataType: 'json',
						contentType: 'application/json',
						type: 'put',
						success: function(result) {
							if(result.succeeded){
							    popup.success("修改成功",function(){
							        parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
							        parent.layui.table.reload("user-table");
							    });
							}else{
							    popup.failure("修改失败");
							}
						}
					})
					return false;
				});
			})
		</script>
		<script>
		</script>
	</body>
</html>
